NodeList subnodelist = Rootnode.getchildnodes ();for (int i = 0; i System.out.println ("Node name of child node:" + Subnodelist.item (i). Getnodename ());SYSTEM.OUT.PRINTLN (node text content of child nodes: + Subnodelist.item (i). Gettextcontent ());}
public void ParseXml03 () {try{Create a Documentbuilder factory instanceDocumentbuilderfactory dbf = Documentbuilderfactory.newinstance ();A new documentbuilder.Documentbuilder db = Dbf.newdocumentb
Yesterday saw a queryselectorall () thing, found that the use of similar to the Getelementsby series, they want to delve into the differences between them, the following is the information found.
PS: The reason to understand this knowledge point
Two days ago, when I reread the JS Dom programming, I saw the chapter on getting the DOM elements, and then I saw getElementsByTagName () and Getelementsbyclassname (), and then I learned about a new Dom api– the modern browser. Queryselectorall (). In m
node is found, the node matching the name attribute is searched. that is, in the HTML4.01 DTD, the browser should first obtain the node through ID. followed by name.In the XHTML 1.0 document, only nodes whose ids match are searched.For the value of the node (id or name) attribute, this method ignores the case sensitivity in HTML documents, while in XHTML documents, the Case sensitivity is required.
The bold part is very important in the above text. Without this as a guide, it is difficul
Like what:
Copy Code code as follows:
var anchors = document.getElementsByTagName ("a");
for (i = 0; i var ele=anchors[i];//takes an element
Some code here
}
The above code represents getting all the link elements in the document and then traversing to do something.
Perhaps you might ask, is this a set of DOM elements obtained by this method not an array? You see, you can get the length attribute directly, and you can also take the corresponding individual element a
For example:
CopyCode The Code is as follows: var anchors = Document. getelementsbytagname ("");
For (I = 0; I VaR ele = anchors [I]; // obtain an element
// Some code here
}
The code above indicates getting all the link elements in the document, and then traversing to do something.Maybe you will ask, isn't the DOM element obtained in this way an array? You can get the Length attribute directly, and obtain the corresponding individual elements based on the index. According to the famous duck t
In a recent reading of JavaScript advanced programming, I saw the phrase: "Understanding nodelist and Htmlcollection is the key to a thorough understanding of the DOM in general." , so I think we should write a blog about nodelist and htmlcollection to get a good understanding and summarize the knowledge points.NodeListNodeList is a collection of nodes (which can contain elements and other nodes), and in th
NodeList objects are very similar in some ways and arrays, and it appears that you can directly use methods inherited from Array.prototype. However, in addition to the Foreach method, NodeList does not have these array-like methods.The inheritance mechanism of JavaScript is prototype-based. Array elements have some array methods (such as ForEach and map) because they have these methods on the prototype chai
Main API that involves getting elementsWhen getting native DOM elements, it mainly involves these Dom APIs (linked to living standard):
Nodeand corresponding setsNodeList
Element(Inheritance Node ) and corresponding setsHTMLCollection
Document(Inherited Node )
Note: The plan supersedes NodeList and HTMLCollection is Elements not currently widely implementedBasic knowledge--NodeList v.s
, but rather a nodelist. NodeList is not an array.What a surprise,right?1. Why is nodelist not an array?The most straightforward way to verify that nodelist is not an array is to try array-specific push and pop Dafa:var anchors = document.getElementsByTagName ("a"); var newele = document.createelement ("a"); // create
, and errors may not occur.However, it is not an array, but a nodelist. Nodelist is not an array.What a surprise, right?
1. Why is nodelist not an array?
Verify whether nodelist is an array. The most direct method may be to try the dedicated push and pop methods of array:
VaR anchors = Document. getelementsbytagna
for loops are not easy to use, and errors may not occur.
However, it is not an Array, but a NodeList. NodeList is not an array.
What a surprise, right?
1. Why is NodeList not an array?
Verify whether NodeList is an Array. The most direct method may be to try the dedicated push and pop methods of Array:
The Code is
In the console typeof NodeList
The result of the execution is: function, and the results are entered in the console nodelist, the effect is as follows:
found that in addition to function inside nothing, so directly new nodelist, the effect is as follows:
Results will be an error, check the relevant introduction of nodelis
The book says: Each node has a ChildNodes property that holds the NodeList object. NodeList is an "object of class array". NodeList is a living, breathing object. Rather than a snapshot of an instant at the time of our first visit. Knowledge Summary:1. NodeList is an array of classes2. The Childbodes property may tak
The following method gets the htmlcollection object
Document. images // All IMG elements document. links // all elements a and area with the href attribute document. anchors // all elements a with the name attribute document. forms // All form elements document. scripts // All script elements document. applets // All applet elements document. embeds // All embed elements document. plugins // document. same as embeds document. getelementbyid ("table "). childrendocument. getelementbyid ("tab
First look at what is nodelist,nodelist and arguments are not normal arrays, they have some basic properties of the array but not exactly an array. Here is the definition found on Mozilla:
This is a commonly used type which be a collection of nodes returned by getElementsByTagName, Getelementsbytagnamens, a D node.childnodes. The list is live and so changes to it internally or externally'll cause the items
In Web front-end programming, we usually take a document.getelementsbytagname approach to get a set of DOM elements of the same label, such as:
var list = document.getElementsByTagName ("li");
for (i = 0; i
First, this group of DOM elements obtained by this method is not an array, but rather a nodelist,nodelist is not an array.We can get its length property directly, and we can also take the correspondi
querySelector()。 This method can be called by the Document or element type.When a method is called with the document type, a matching element is found within the scope of the querySelector() documentation element, and when the method is called with the element type querySelector() , only the matching elements are found in the descendant elements of the elements. If no matching elements exist, both types return NULL when the method is called.querySelectorAll()。 This method can be called by the Do
Node objects are a single node, but sometimes a data structure is required to accommodate multiple nodes. The DOM provides two interfaces for deploying a collection of such nodes, namely NodeList and htmlcollection
Definition on MDN:
NodeList:
The NodeList object is a collection of nodes (collections of nodes) returned by the Node.childnodes and
When getting native DOM elements, it mainly involves these Dom APIs (linked to living standard):
Nodeand corresponding setsNodeList
Element(Inheritance Node ) and corresponding setsHTMLCollection
Document(Inherited Node )
Note: The plan supersedes NodeList and HTMLCollection is Elements not currently widely implementedBasic knowledge--NodeList v.s. htmlcollectionIn different versions o
Convert nodelist to Arrays (compatibility)function Arrayofnodes (nodes) { varnull; Try { = Array.prototype.slice.call (nodes,0); } Catch (ex) { new Array (); for (var i=0,len=nodes.length; i ) { arr.push (nodes[i]); } } return arr;}nodes non-JScript objects in IE8 's previous browsers, but COM objects, soArray.prototype.slice.call (nodes,0);Will go wrongCatch is required to catch the error and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.